package com.example.gyj.dao;

import com.example.gyj.entity.OrderInfo;
import com.example.gyj.entity.SeckillOrder;
import org.apache.ibatis.annotations.*;

/**
 * Created by Gao on 2018/10/21.
 */
@Mapper
public interface OrderDao {

    @Select("select * from s_order where user_id = #{userId} and goods_id = #{goodsId}")
    public SeckillOrder getSeckillOrderByUserIdAndGoodsId(@Param("userId") long userId, @Param("goodsId") long goodsId);

    @Insert("insert into order_info (user_id,goods_id,delivery_addr_id,goods_name,goods_count,goods_price,order_channel,status,create_date) "
            + "values(#{userId},#{goodsId},#{deliveryAddrId},#{goodsName},#{goodsCount},#{goodsPrice},#{orderChannel},#{status},#{createDate})")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class, before = false, statement = "select last_insert_id()")
    public long insertOrder(OrderInfo orderInfo);

    @Insert("insert into s_order (user_id,order_id,goods_id) values(#{userId},#{orderId},#{goodsId})")
    public void insertSeckillOrder(SeckillOrder seckillOrder);

    @Select("select * from s_order where id = #{orderId}")
    public OrderInfo getOrderById(@Param("orderId") long orderId);

    @Delete("delete from order_info")
    public void deleteOrders();

    @Delete("delete from s_order")
    public void deleteSeckillOrders();
}
